using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Application.DTOs;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 翻译应用服务接口
    /// 提供多语言翻译管理的业务逻辑
    /// </summary>
    public interface ITranslationAppService
    {
        /// <summary>
        /// 获取分页的翻译列表
        /// </summary>
        /// <param name="query">查询参数</param>
        /// <returns>分页的翻译列表</returns>
        Task<PagedResultDto<TranslationDto>> GetPagedListAsync(PagedQueryDto query);
        
        /// <summary>
        /// 根据语言获取翻译列表
        /// </summary>
        /// <param name="languageId">语言ID</param>
        /// <param name="group">翻译分组</param>
        /// <returns>翻译列表</returns>
        Task<List<TranslationDto>> GetByLanguageAsync(long languageId, string? group = null);
        
        /// <summary>
        /// 根据键值获取翻译
        /// </summary>
        /// <param name="key">翻译键</param>
        /// <param name="languageCode">语言代码</param>
        /// <returns>翻译值</returns>
        Task<string?> GetTranslationAsync(string key, string languageCode);
        
        /// <summary>
        /// 批量获取翻译
        /// </summary>
        /// <param name="keys">翻译键列表</param>
        /// <param name="languageCode">语言代码</param>
        /// <returns>翻译字典</returns>
        Task<Dictionary<string, string>> GetTranslationsAsync(List<string> keys, string languageCode);
        
        /// <summary>
        /// 根据分组获取翻译
        /// </summary>
        /// <param name="group">翻译分组</param>
        /// <param name="languageCode">语言代码</param>
        /// <returns>翻译字典</returns>
        Task<Dictionary<string, string>> GetByGroupAsync(string group, string languageCode);
        
        /// <summary>
        /// 根据ID获取翻译详情
        /// </summary>
        /// <param name="id">翻译ID</param>
        /// <returns>翻译详情</returns>
        Task<TranslationDto?> GetByIdAsync(long id);
        
        /// <summary>
        /// 创建翻译
        /// </summary>
        /// <param name="dto">翻译数据</param>
        /// <returns>创建的翻译</returns>
        Task<TranslationDto> CreateAsync(TranslationDto dto);
        
        /// <summary>
        /// 更新翻译
        /// </summary>
        /// <param name="id">翻译ID</param>
        /// <param name="dto">更新的翻译数据</param>
        /// <returns>更新后的翻译</returns>
        Task<TranslationDto> UpdateAsync(long id, TranslationDto dto);
        
        /// <summary>
        /// 删除翻译
        /// </summary>
        /// <param name="id">翻译ID</param>
        /// <returns>删除结果</returns>
        Task<bool> DeleteAsync(long id);
        
        /// <summary>
        /// 批量删除翻译
        /// </summary>
        /// <param name="ids">翻译ID列表</param>
        /// <returns>删除结果</returns>
        Task<bool> BatchDeleteAsync(List<long> ids);
        
        /// <summary>
        /// 批量创建翻译
        /// </summary>
        /// <param name="translations">翻译数据列表</param>
        /// <returns>创建结果</returns>
        Task<List<TranslationDto>> BatchCreateAsync(List<TranslationDto> translations);
        
        /// <summary>
        /// 批量更新翻译
        /// </summary>
        /// <param name="translations">翻译数据</param>
        /// <returns>更新结果</returns>
        Task<bool> BatchUpdateAsync(Dictionary<long, string> translations);
        
        /// <summary>
        /// 自动翻译
        /// </summary>
        /// <param name="sourceLanguageCode">源语言代码</param>
        /// <param name="targetLanguageCode">目标语言代码</param>
        /// <param name="keys">翻译键列表</param>
        /// <returns>自动翻译结果</returns>
        Task<List<TranslationDto>> AutoTranslateAsync(string sourceLanguageCode, string targetLanguageCode, List<string>? keys = null);
        
        /// <summary>
        /// 审核翻译
        /// </summary>
        /// <param name="id">翻译ID</param>
        /// <param name="approved">是否通过审核</param>
        /// <param name="comment">审核意见</param>
        /// <returns>审核结果</returns>
        Task<bool> ReviewAsync(long id, bool approved, string? comment = null);
        
        /// <summary>
        /// 批量审核翻译
        /// </summary>
        /// <param name="ids">翻译ID列表</param>
        /// <param name="approved">是否通过审核</param>
        /// <param name="comment">审核意见</param>
        /// <returns>审核结果</returns>
        Task<bool> BatchReviewAsync(List<long> ids, bool approved, string? comment = null);
        
        /// <summary>
        /// 导出翻译数据
        /// </summary>
        /// <param name="languageId">语言ID</param>
        /// <param name="group">翻译分组</param>
        /// <param name="format">导出格式 (json, csv, excel)</param>
        /// <returns>导出数据</returns>
        Task<byte[]> ExportAsync(long languageId, string? group = null, string format = "json");
        
        /// <summary>
        /// 导入翻译数据
        /// </summary>
        /// <param name="languageId">语言ID</param>
        /// <param name="data">导入数据</param>
        /// <param name="format">数据格式</param>
        /// <param name="overwrite">是否覆盖已有翻译</param>
        /// <returns>导入结果</returns>
        Task<List<TranslationDto>> ImportAsync(long languageId, byte[] data, string format = "json", bool overwrite = false);
        
        /// <summary>
        /// 同步翻译
        /// </summary>
        /// <param name="sourceLanguageId">源语言ID</param>
        /// <param name="targetLanguageId">目标语言ID</param>
        /// <param name="keys">同步的翻译键</param>
        /// <returns>同步结果</returns>
        Task<bool> SyncAsync(long sourceLanguageId, long targetLanguageId, List<string>? keys = null);
        
        /// <summary>
        /// 获取待翻译的条目
        /// </summary>
        /// <param name="languageId">语言ID</param>
        /// <param name="limit">限制数量</param>
        /// <returns>待翻译列表</returns>
        Task<List<TranslationDto>> GetPendingTranslationsAsync(long languageId, int limit = 100);
        
        /// <summary>
        /// 获取待审核的条目
        /// </summary>
        /// <param name="languageId">语言ID</param>
        /// <param name="limit">限制数量</param>
        /// <returns>待审核列表</returns>
        Task<List<TranslationDto>> GetPendingReviewsAsync(long languageId, int limit = 100);
        
        /// <summary>
        /// 检查翻译键是否存在
        /// </summary>
        /// <param name="key">翻译键</param>
        /// <param name="languageId">语言ID</param>
        /// <param name="excludeId">排除的翻译ID</param>
        /// <returns>是否存在</returns>
        Task<bool> ExistsAsync(string key, long languageId, long? excludeId = null);
        
        /// <summary>
        /// 搜索翻译
        /// </summary>
        /// <param name="keyword">搜索关键字</param>
        /// <param name="languageId">语言ID</param>
        /// <param name="searchInValues">是否在翻译值中搜索</param>
        /// <returns>搜索结果</returns>
        Task<List<TranslationDto>> SearchAsync(string keyword, long? languageId = null, bool searchInValues = true);
        
        /// <summary>
        /// 获取翻译统计
        /// </summary>
        /// <param name="languageId">语言ID</param>
        /// <returns>统计信息</returns>
        Task<Dictionary<string, int>> GetStatisticsAsync(long? languageId = null);
        
        /// <summary>
        /// 清理未使用的翻译
        /// </summary>
        /// <param name="languageId">语言ID</param>
        /// <returns>清理数量</returns>
        Task<int> CleanupUnusedAsync(long? languageId = null);
        
        /// <summary>
        /// 查找缺失的翻译
        /// </summary>
        /// <param name="sourceLanguageId">源语言ID</param>
        /// <param name="targetLanguageId">目标语言ID</param>
        /// <returns>缺失的翻译键</returns>
        Task<List<string>> FindMissingTranslationsAsync(long sourceLanguageId, long targetLanguageId);
    }
}
